//
//  HongBaoView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/9.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "HongBaoView.h"
#import "JTCSM.h"
static CGFloat space = 0.042;
//static CGFloat top = 0.07;
static CGFloat headerWidth = 0.2227;
static CGFloat footerWidth = 0.6788;
//static CGFloat Height = 0.7022;
static CGFloat BILI = 0.341;

@interface HongBaoView (){
    UILabel *mongeyLabel;
    UILabel *ShuoMingLabel;
    UILabel *intrudiuceLabel;
    UILabel *timeLabel;
    CGFloat viewWidth;
    CGFloat viewHeight;
    
    UIImageView *statusImageV;
}

@end
@implementation HongBaoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        viewWidth = frame.size.width;
        self.frame = CGRectMake(frame.origin.x, frame.origin.y, viewWidth, viewWidth*BILI);
        viewHeight = self.frame.size.height;
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, viewWidth, viewWidth*BILI)];
        imageView.image = [UIImage imageNamed:@"bg_banner7@2x.png"];
        [self addSubview:imageView];
        
        mongeyLabel = [UILabel initWithFrame:CGRectZero text:@"" font:20 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(227, 68, 40, 1) backgroundColor:nil];
        [self addSubview:mongeyLabel];
        
        ShuoMingLabel = [UILabel initWithFrame:CGRectZero text:@"" font:14 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(193, 193, 193, 1) backgroundColor:nil];
        [self addSubview:ShuoMingLabel];
        
        intrudiuceLabel = [UILabel initWithFrame:CGRectZero text:@"" font:18 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [self addSubview:intrudiuceLabel];
        
        timeLabel = [UILabel initWithFrame:CGRectZero text:@"" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(193, 193, 193, 1) backgroundColor:nil];
        [self addSubview:timeLabel];
        CGFloat imagesize = viewHeight*3/4;
        statusImageV = [[UIImageView alloc]initWithFrame:CGRectMake(viewWidth-viewWidth*space-imagesize, viewHeight/4, imagesize, imagesize)];
        [statusImageV setImage:[UIImage imageNamed:@"bg_05@2x.png"]];
        [statusImageV setHighlightedImage:[UIImage imageNamed:@"bg_06@2x.png"]];
        [self addSubview:statusImageV];
        
    }
    
    return self;
}

- (void)setValueWithModel:(BounsModel *)model{
    mongeyLabel.text = [NSString stringWithFormat:@"%@",model.price];
    CGRect rect = [df labelHeightWithContent:mongeyLabel.text width:viewWidth*headerWidth label:mongeyLabel];
    ShuoMingLabel.text = @"还款金";
    CGRect rect1 = [df labelHeightWithContent:ShuoMingLabel.text width:viewWidth*headerWidth label:ShuoMingLabel];
    CGFloat changeTop = 5;
    CGFloat ViewTop = (viewHeight-rect.size.height-rect1.size.height)/2-changeTop;
    mongeyLabel.frame = CGRectMake(viewWidth*space, ViewTop, viewWidth*headerWidth, rect.size.height);
    ShuoMingLabel.frame = CGRectMake(viewWidth*space, KVIEW_Y(mongeyLabel)+changeTop*2, viewWidth*headerWidth, rect1.size.height);
    
    
    intrudiuceLabel.text = model.title;
    timeLabel.text =[NSString stringWithFormat:@"有效期：%@",((model.ub_id == nil || [model.ub_id isEqualToString:@""])?model.bonus_end:model.use_end)];
    intrudiuceLabel.frame = CGRectMake(KVIEW_X(mongeyLabel)+15, ViewTop, viewWidth*footerWidth, rect.size.height);
    timeLabel.frame = CGRectMake(KVIEW_X(mongeyLabel)+15, KVIEW_Y(intrudiuceLabel)+changeTop*2, viewWidth*footerWidth, rect1.size.height);
    
    if (model.is_receive == nil || [model.is_receive isEqualToString:@""]) {
        statusImageV.highlighted = NO;
        [statusImageV setImage:[UIImage imageNamed:@""]];

    }else{
        if ( [model.is_receive integerValue] ==1) {
            statusImageV.highlighted = YES;
        }else if ( [model.is_receive integerValue] ==0) {
            statusImageV.highlighted = NO;
        }
 
    }
}

@end
